# -----------------------------------------
# Oratr makefile
# -----------------------------------------

CFLAGS_C = $(filter-out -include "sdk.h",$(CFLAGS))

# -----------------------------------------

# MAKE_DEP = -MMD -MT $@ -MF $(@:.o=.d)

CFLAGS = -Wall -Wextra -Werror -pedantic -DORATR_USE_HTTP -DORATR_DEVELOPMENT
#CFLAGS = -Wall -Wextra -Werror -pedantic -DORATR_USE_HTTP
INCLUDES = 
LDFLAGS =  -s
RCFLAGS = 
LDLIBS = $(T_LDLIBS)  -lstdc++
VPATH = src

LINK_exe = gcc -o $@ $^ $(LDFLAGS) $(LDLIBS)
LINK_con = gcc -o $@ $^ $(LDFLAGS) $(LDLIBS)
LINK_dll = gcc -o $@ $^ $(LDFLAGS) $(LDLIBS) -shared
LINK_lib = rm -f $@ && ar rcs $@ $^
COMPILE_c = gcc $(CFLAGS_C) -o $@ -c $< $(MAKEDEP) $(INCLUDES)
COMPILE_cpp = g++ $(CFLAGS) -o $@ -c $< $(MAKEDEP) $(INCLUDES)
COMPILE_rc = windres $(RCFLAGS) -J rc -O coff -i $< -o $@ -I$(dir $<)

%.o : %.c ; $(COMPILE_c)
%.o : %.cpp ; $(COMPILE_cpp)
%.o : %.cxx ; $(COMPILE_cpp)
%.o : %.rc ; $(COMPILE_rc)
.SUFFIXES: .o .d .c .cpp .cxx .rc

all: all.before all.targets all.after

all.before :
	-
all.after : $(FIRST_TARGET)
	
all.targets : target

clean :
	rm -fv $(clean.OBJ)
	rm -fv $(DEP_FILES)

.PHONY: all clean distclean

# -----------------------------------------
# Build target
# -----------------------------------------

target.BIN = ./Oratr
target.OBJ = \
	src/os.o \
	src/alias.o \
	src/array.o \
	src/bitypedefs.o \
	src/builtins.o \
	src/environment.o \
	src/errors.o \
	src/files.o \
	src/http.o \
	src/http_download.o \
	src/io.o \
	src/lexer.o \
	src/main.o \
	src/man.o \
	src/math.o \
	src/parser.o \
	src/preprocessor.o \
	src/time.o \
	src/utils.o \
	src/variables.o \
	src/win_tcpsocket.o
DEP_FILES += $(target.OBJ,.o=.d)
clean.OBJ += $(target.BIN) $(target.OBJ)

target : target.before $(target.BIN) target.after_always
target : CFLAGS += -O2  -Os
target : INCLUDES += 
target : RCFLAGS += 
target : LDFLAGS += -s   
target : T_LDLIBS = 
ifdef LMAKE
target : CFLAGS -= -O1 -O2 -g -pipe
endif

target.before :
	
target.after_always : $(target.BIN)
	
$(target.BIN) : $(target.OBJ)
	$(LINK_con)
	

# -----------------------------------------

ifdef MAKE_DEP
-include $(DEP_FILES)
endif